package com.lsk.member;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.lsk.task.AgentTask;
import com.lsk.util.ReturnData;
import com.lsk.util.Syslog;

/**
 * Created by Administrator on 2018-11-20.
 */
public class MemberController extends Controller {
    public void memberList(){

        renderJsp("memberList.jsp");
    }

    /**
     * 拉黑会员
     */
    public void forbid(){

        String memberId=getPara("memberId");

        String checked=getPara("checked");

        Record record=new Record().set("id",memberId);

        if ("true".equals(checked)){

            record.set("forbid",1);
        }else {

            record.set("forbid",0);
        }
        Db.update("yx_member","id",record);
        renderJson(new ReturnData(true));
    }

    /**
     * 成为代理商
     */
    public void agent(){
        String memberId=getPara("memberId");

        String checked=getPara("checked");

        Record record=new Record().set("id",memberId);

        if ("true".equals(checked)){

            AgentTask agentTask=new AgentTask(memberId);
            agentTask.run();
            record.set("agent",0);
            Db.update("yx_member","id",record);

        }else {
            record.set("agent",1);
            int delete = Db.delete("delete from yx_member_rebates where memberId='" + memberId + "'");
            if (delete>0){
                Syslog.info("返利配置已清除");
            }else{
                Syslog.info("返利配置未清除");
            }
        }
        Db.update("yx_member","id",record);
        renderJson(new ReturnData(true));
    }

}
